import guid from './guid'
import page from './page'

/**
 * value ：要搜索的值
 * array ： 被搜索的数组
 * type ： 类型，true全等 ，false非全等(默认)
 */
function inArray(value, array, type = false) {
	let ok = -1;
	for (var i = 0; i < array.length; i++) {
		if (value == array[i]) {
			++ok;
		}
	}
	if (type) {
		return ok == array.length
	} else {
		return ok >= 0;
	}
}

function getChildrenByList(key, children, filter = undefined) {
	let list = [];
	for (let i = 0; i < children.length; i++) {
		let item = children[i];
		if (filter != undefined) {
			if(filter(item) == false){
				continue;
			}
		}
		list.push(item);
		if (item[key] == undefined) {
			continue;
		}
		if (item[key] == null) {
			continue;
		}
		if (typeof item[key] != 'object') {
			continue;
		}
		let items = getChildrenByList(key, item[key], filter);
		for (let j = 0; j < items.length; j++) {
			list.push(items[j]);
		}
	}
	return list;
}


export default {
	guid,
	page,
	inArray,
	getChildrenByList,
}